#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Author :   Liang Kang
@Contact:   gangkanli1219@163.com
@Time   :   2018/7/24 9:45
@Desc   :
"""
from pathlib import Path
from dltools.data import BaseFileReader
from dltools.utils import log


class DataReader(BaseFileReader):

    def __init__(self, root, logger, display=10):
        """
        读取文件夹下所有文件

        Parameters
        ----------
        root: 根目录
        logger: 日志对象
        display: 每扫描多少文件显示一次

        Returns
        -------

        """
        if logger is not None:
            logger = logger.getChild('DataReader')
        else:
            logger = log.get_console_logger('DataReader')
        super(DataReader, self).__init__(root, display=display, logger=logger)

    def _filter(self, file: Path):
        if file.suffix in ('.jpg', '.JPG', '.png', '.PNG'):
            self._buf_data = {'image': str(file),
                              'xml': str(file.with_name(file.stem + '.xml'))}
            return True
        else:
            return False
